﻿Imports Microsoft.Win32

Public Class ThisAddIn
    Public Shared dsWebServices As System.Data.DataSet = Nothing
    Dim WithEvents objButton As Office.CommandBarButton

    Sub LoadWebServices()
        Dim filename As String = ""
        Dim fsReadXML As System.IO.FileStream = Nothing


        Dim row1() As String = {"http://www.earthtools.org/timezone/{0}/{1}", "//timezone/offset"}
        Dim row2() As String = {"http://ws.geonames.org/timezone?lat={0}&lng={1}", "//geonames/timezone/gmtOffset"}
        Dim keyValue() As String
        Dim rootValue As String = "HKEY_CURRENT_USER\Software\Outlook2007DIT\TZWebServices"
        Dim rowId As Integer = 1
        Dim finished As Boolean = False
        Dim exists As Boolean = False

        dsWebServices = New System.Data.DataSet
        dsWebServices.Tables.Add("TZWebService")
        With dsWebServices.Tables("TZWebService")
            .Columns.Add("WebServiceFormatString")
            .Columns.Add("WebServiceResponsePath")
        End With

        Do Until finished = True

            Try
                keyValue = My.Computer.Registry.GetValue(rootValue, rowId, "")
                dsWebServices.Tables("TZWebService").Rows.Add(keyValue)
                exists = True
            Catch ex As Exception
                finished = True
            End Try
            rowId = rowId + 1
        Loop
        If exists = False Then
            My.Computer.Registry.SetValue(rootValue, "1", row1)
            My.Computer.Registry.SetValue(rootValue, "2", row2)
            With dsWebServices.Tables("TZWebService")
                .Rows.Add(row1)
                .Rows.Add(row2)
            End With
        End If
    End Sub
    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
        LoadWebServices()
        CreateRibbonExtensibilityObject()
        'Dim oExp As Outlook.Explorer
        'Dim oBar As Office.CommandBar

        'oExp = Globals.ThisAddIn.Application.ActiveExplorer
        'oBar = oExp.CommandBars.Item("Standard")
        'objButton = oBar.Controls.Add(, , , 1, True)
        'With objButton
        '    .FaceId = 59
        '    .Caption = "My Button"

        '    .Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption

        '    ' The OnAction property is optional but recommended. 
        '    ' It should be set to the ProgID of the add-in, such that if
        '    ' the add-in is not loaded when a user presses the button,
        '    ' Outlook loads the add-in automatically and then raises
        '    ' the Click event for the add-in to handle. 

        '    '.OnAction = "!<" & AddInInst.ProgId & ">"
        'End With

    End Sub

    Private Sub objButton_Click(ByVal Ctrl As Office.CommandBarButton, _
       ByVal CancelDefault As Boolean)

        MsgBox("Hello World")

    End Sub
  
    Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown

    End Sub
    Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility
        Return New Ribbon()
    End Function
End Class
